﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NetFramework.Utility;
using System.IO;

namespace NetFramework.Configuration
{
    public class FileConfigParameter : IConfigParameter
    {
        public FileConfigParameter(string name, string fileOrFilePattern)
            : this(name, name, fileOrFilePattern, true)
        {
            
        }

        public FileConfigParameter(string name, string fileOrFilePattern, bool cacheable)
            : this(name, name, fileOrFilePattern, true)
        {

        }

        public FileConfigParameter(string name, string cacheKey, string fileOrFilePattern)
            : this(name, cacheKey, fileOrFilePattern, true)
        {
        }

        public FileConfigParameter(string name, string cacheKey, string fileOrFilePattern, bool cacheable)
        {
            this.Name = name;
            this.CacheKey = cacheKey;
            this.Cacheable = cacheable;
            GetFiles(fileOrFilePattern);
        }

        public bool Cacheable
        {
            get;
            private set;
        }

        public string CacheKey
        {
            get;
            private set;
        }

        public string Name
        {
            get;
            private set;
        }

        public string[] Files
        {
            get;
            private set;
        }

        private void GetFiles(string fileOrFilePattern)
        {
            string fullPath = PathUtils.GetFullPath(fileOrFilePattern);
            string fileName = Path.GetFileName(fullPath);
            string fullDir = Path.GetDirectoryName(fullPath);

            this.Files = Directory.GetFiles(fullDir, fileName);
        }
    }
}
